package com.bawei.libs_base.mvvm

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import java.lang.reflect.ParameterizedType

abstract class BaseViewFragment<VDB: ViewDataBinding>: Fragment() {
    private val type by lazy {
        (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments
    }

    val binding by lazy {
        (type[0] as Class<VDB>).getMethod("inflate" ,LayoutInflater::class.java).invoke(null ,layoutInflater) as VDB
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        initView()
        initData()
        return binding.root
    }

    abstract fun initView()

    abstract fun initData()

}